package com.haina.shop.controller.category;

import com.haina.shop.result.ServiceResult;
import com.haina.shop.service.CategoryService;
import com.haina.shop.vo.CategoryVo;
import com.haina.shop.vo.PageVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class PageCategoryController {

    @Resource
    private CategoryService categoryService;
    @GetMapping("/prod/pageProd")
    public ServiceResult pageProd(@RequestParam("categoryId")long categoryId){
        PageVo pageVo=new PageVo();
        pageVo.setCurrent(Long.parseLong("1"));
        pageVo.setSize(Long.parseLong("10"));
        PageVo pageVo1 = categoryService.pageSelect(categoryId, pageVo);

        return ServiceResult.success(pageVo1);
    }

    @GetMapping("/category/categoryInfo")
    public ServiceResult category(@RequestParam(defaultValue = "0",value = "parentId")long parentId){
        CategoryVo categoryVo = new CategoryVo();
        categoryVo.setParentId(parentId);
        List<CategoryVo> category = categoryService.category(parentId);
        return ServiceResult.success(category);
    }

}
